package com.mike.util;

/**
 * IntConverter
 *
 * This class provides methods to convert int into byte array and
 * byte array back into int.
 */
public class IntConverter {

	public static int bytes2Int(byte[] b) {
		int temp = 0;
		int n = 0;
		for (int i = 0; i < 4; i++) {
			n <<= 8;
			temp = b[i] & 0xff;
			n |= temp;
		}
		return n;
	}
	
	/**
	 * Method converting int into byte array.
	 * @param number The int value to be converted.
	 *
	 */
	public static byte[] toByteArray(int number) {
		byte[] b = new byte[4];
		int temp = number;
		for (int i = b.length - 1; i >= 0; i--) {
			b[i] = new Integer(temp & 0xff).byteValue();
			temp >>= 8;
		}
		return b;
	}


}